#ifndef _HDR_GATEWAY_SELECTION_INC
#define _HDR_GATEWAY_SELECTION_INC

#include "adventure_path.h"
#include "creature_array.h"
#include "gateway_base.h"

template <typename gateway_type > 
t_gateway_base const* ai_select_gateway_exit( t_adventure_path const& path, gateway_type& gateway_list, t_gateway_base const* this_gateway, t_creature_array* army, t_adv_map_point dest_point )
{
	int size = path.size();
	for (int i = (size - 1); i > 0; i--)
	{
		t_adventure_path_point const& path_point = path[i];
		if ( dest_point == path_point )
		{
			for (int j=0; j < gateway_list.size(); j++)
			{
				if ( this_gateway != gateway_list[j].get() )
				{
					t_adv_map_point gateway_destination; 
					gateway_destination.on_bridge = false;
					gateway_list[j]->find_adjacent_space(gateway_destination, *army);
					if ( path[i - 1] == gateway_destination )
					{
						return gateway_list[j];
					}
				}
			}
			break;
		}
	}
	return NULL;
}

#endif